package com.riven.bilibilidemo.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.riven.bilibilidemo.R;
import com.riven.bilibilidemo.activity.ZhiBoActivity;
import com.riven.bilibilidemo.bean.BeanList;

import java.util.List;

/**
 * Created by S on 2017/3/9.
 */

public class MyTwoRecyclerView extends RecyclerView.Adapter<MyTwoRecyclerView.MyViewHolder>{


    private final Context context;

    private final List<BeanList.DatashouyeBean.PartitionsshouyeBean.LivesshouyeBeanX> lives;
    private CardView cardView;

    public MyTwoRecyclerView(Context context, List<BeanList.DatashouyeBean.PartitionsshouyeBean.LivesshouyeBeanX> lives) {
   
        this.context = context;
        this.lives = lives;
    }

    @Override
    public MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = View.inflate(context, R.layout.zhibo_cardview, null);
        cardView = (CardView) view.findViewById(R.id.cardView);
        cardView.setRadius(8);//设置图片圆角的半径大小

        cardView.setCardElevation(8);//设置阴影部分大小

        cardView.setContentPadding(10,10,10,10);//设置图片距离阴影大小
        return new MyViewHolder(view);
    }

    @Override
    public void onBindViewHolder(MyViewHolder holder, final int position) {
    Glide.with(context).load(lives.get(position).getCover().getSrc()).into(holder.item2_img);
    Glide.with(context).load(lives.get(position).getOwner().getFace()).into(holder.item2_touxiang);
    holder.item2_title.setText(lives.get(position).getTitle());
    holder.item2_name.setText(lives.get(position).getOwner().getName());

       if(lives.get(position).getOnline()>=10000){
           int i = lives.get(position).getOnline()/ 10000;
           holder.item2_id.setText(i+"万");
       }
        holder.ll.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ZhiBoActivity.class);
               intent.putExtra("title",lives.get(position).getTitle());
                intent.putExtra("name",lives.get(position).getOwner().getName());
                intent.putExtra("online",lives.get(position).getOnline());
                intent.putExtra("image",lives.get(position).getCover().getSrc());
                context.startActivity(intent);
            }
        });
}
    @Override
    public int getItemCount() {
        return 4;
    }

    class MyViewHolder extends RecyclerView.ViewHolder{

        private final ImageView item2_img;
        private final ImageView item2_touxiang;
        private final TextView item2_title;
        private final TextView item2_name;
        private final TextView item2_id;
        private final LinearLayout ll;

        public MyViewHolder(View itemView) {
            super(itemView);

            item2_img = (ImageView) itemView.findViewById(R.id.item2_img);
            item2_touxiang = (ImageView) itemView.findViewById(R.id.item2_touxiang_img);
            item2_title = (TextView) itemView.findViewById(R.id.item2_title);
            item2_name = (TextView) itemView.findViewById(R.id.item2_name);
            item2_id = (TextView) itemView.findViewById(R.id.item2_id);
            ll = (LinearLayout) itemView.findViewById(R.id.ll);
        }
    }
}
